package com.rz.admin.controller;

import com.rz.admin.entity.Res;
import com.rz.admin.service.IResService;
import com.rz.core.kit.RespKit;
import com.rz.core.resp.ResultResp;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("resource")
public class ResCtrl {

    @Resource
    private IResService resService;

    @PostMapping("findAll")
    public ResultResp findAll(){
        List<Res> resList = resService.list();
        return RespKit.success(resService.buildResTree(resList));
    }

    @PostMapping("save")
    public ResultResp save(@RequestBody Res res){
        return RespKit.success(resService.onSave(res));
    }

    @PostMapping("delete/{id}")
    public ResultResp delete(@PathVariable Integer id){
        return RespKit.success(resService.removeById(id));
    }
}
